//
//  KLRealNameCertifyViewController.m
//  KISSLOCK
//
//  Created by RaoBo on 2017/4/20.
//  Copyright © 2017年 陈宾鹏. All rights reserved.
//

#import "KLRealNameCertifyViewController.h"
#import "HemaConst.h"
#import "KLHelp.h"
#import "KLCertificationViewController.h"
#import "KLEditViewController.h" 
#import "JRToast.h"

@interface KLRealNameCertifyViewController () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, copy) NSString *name; // 用于记录姓名
@property (nonatomic, copy) NSString *identityCard; // 用于记录身份证
@end

@implementation KLRealNameCertifyViewController
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UI_View_Width, UI_View_Height) style:(UITableViewStylePlain)];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 初始化导航条
    [self setNavAndTableView];
}
- (void)viewDidAppear:(BOOL)animated {

    // 先在本地存在，接口写好了再改
    self.name = [[NSUserDefaults standardUserDefaults] objectForKey:@"realName"];
    self.identityCard = [[NSUserDefaults standardUserDefaults] objectForKey:@"identityCard"];
    [self.tableView reloadData];
    
}

- (void)setNavAndTableView {
    self.title = @"实名认证";
    self.view.backgroundColor = RGB_UI_COLOR(242, 242, 242);

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init]; // 去掉cell 小格子
    // 添加到view
    [self.view addSubview:self.tableView];
    
    [KLHelp navSet:self doBackHandler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:(UIControlEventTouchUpInside)];
    } nextStepHandler:^(UIButton *nextStepBtn) {
        [nextStepBtn addTarget:self action:@selector(nextStep:) forControlEvents:(UIControlEventTouchUpInside)];
    }];
}
- (void)doBack:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
// 下一步
- (void)nextStep:(UIButton *)sender {
    
        KLCertificationViewController *certifiVC = [[KLCertificationViewController alloc] initWithNibName:@"KLCertificationViewController" bundle:nil];
        certifiVC.pictureType = IdentifyCardPictureFront; // 第一次为身份证正面
//    cardVC.identityCardMode = LTIdentityCardModeId;

        certifiVC.title = @"实名认证";
        [self.navigationController pushViewController:certifiVC animated:YES];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:cellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"真实姓名:";
        cell.detailTextLabel.text = self.name;
    }else if (indexPath.row == 1) {
        cell.textLabel.text = @"身份证号:";
        cell.detailTextLabel.text = self.identityCard;
    }else {
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont systemFontOfSize:12.0];
        cell.textLabel.text = @"\n请确认真实姓名和有效身份证号码有效且统一;";
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    KLEditViewController *editVC = [[KLEditViewController alloc] init];
    if (indexPath.row == 0) {
        editVC.title = @"编辑真实姓名";
        [self.navigationController pushViewController:editVC animated:YES];
    }else if (indexPath.row == 1) {
        editVC.title = @"编辑身份证号";
        [self.navigationController pushViewController:editVC animated:YES];
    }
}


@end
